#ifndef _GB_UAS_H_
#define _GB_UAS_H_

#include <eXosip2/eXosip.h>

#define MAX_NAME_LEN 128
#define MAX_ID_LEN   32
#define MAX_IP_LEN   64
#define MAX_PORT_LEN 16

#define SINGLE_SEND_CNT		4

#define MSG_TYPE_NONE		0
#define MSG_TYPE_DEVLIST	10
#define MSG_TYPE_DEVINFO	11
#define MSG_TYPE_DEVSTAT	12
#define MSG_TYPE_FILELIST	13

#define MD_CTL_PLAY		1
#define MD_CTL_PLAYBACK	2
#define MD_CTL_DOWNLOAD 3

#define MD_CTL_CANINVITE 100

#define MAX_SIP_CALL   (64UL)

struct MediaDesc;
struct UASContext;
struct DeviceInfo;
struct DeviceStatus;
struct RecordItemInfo;
struct UASCallback;
struct UASContext;

struct MediaDesc
{
	char ServerIp[MAX_IP_LEN];
	char MediaPort[MAX_PORT_LEN];
	int  Speed;
	unsigned SSRC;
	int MediaCtrlType;
	long long StartTime;
	long long StopTime;
	char MediaSrcDevID[MAX_ID_LEN];
	char StreamSendSQN[MAX_ID_LEN];
	char MediaDstDevID[MAX_ID_LEN];
	char StreamRecverSQN[MAX_ID_LEN];
};

struct DeviceInfo
{
	char DeviceId[MAX_ID_LEN];
	char DeviceName[MAX_NAME_LEN];
	char DeviceType[MAX_ID_LEN];
	char DeviceManufacturer[MAX_ID_LEN];
	char DeviceModel[MAX_ID_LEN];
	char DeviceOwner[MAX_ID_LEN];
	char DeviceCivilCode[MAX_ID_LEN];
	char DeviceAddress[MAX_ID_LEN];
	char DeviceFirmware[MAX_ID_LEN];
	char DeviceParentId[MAX_ID_LEN];
	BOOL OnLine;
};

struct DeviceStatus
{
	char DeviceId[MAX_ID_LEN];
	char Online[MAX_ID_LEN];
	char Status[MAX_ID_LEN];
};

struct RecordListCmd
{
	char DeviceId[MAX_ID_LEN];
	char DeviceName[MAX_NAME_LEN];
	char CmdSQN[MAX_ID_LEN];
	char FilePath[MAX_PATH];
	char StartTime[MAX_ID_LEN];
	char EndTime[MAX_ID_LEN];
	char RecorderId[MAX_ID_LEN];

};

struct RecordItemInfo
{
	char StartTime[MAX_ID_LEN];
	char EndTime[MAX_ID_LEN];
};

struct UASCallback
{
	int (*getDeviceInfo)(UASContext *ctx, vector<DeviceInfo*> &devices);
	int (*getOfflineDeviceInfo)(UASContext *ctx, vector<DeviceInfo> & devices);
	int (*playControl)(UASContext *ctx, int callId, int dialogId, char *control_type, char *play_speed, char *pause_time, char *range_start, char *range_end);
	int (*mediaControl)(UASContext *ctx, int callId, int dialogId, const MediaDesc& mdesc);
	int (*getRecordTime)(UASContext *ctx, const char *deviceId, const char *startTime, const char *endTime, const char* path, const char *recorderid);
	int (*closeDialogue) (UASContext *ctx, int callId, int dialogId);
};


struct UASContext
{
	char UserId[MAX_ID_LEN];
	char UserPwd[MAX_ID_LEN];
	char LocalIp[MAX_IP_LEN];
	char LocalPort[MAX_PORT_LEN];
	char ServerId[MAX_ID_LEN];
	char ServerIp[MAX_IP_LEN];
	char ServerPort[MAX_PORT_LEN];

	int  RegisterId;
	int  QuitFlag;
	int  NotifySendFlag;
	int  SubscribDID;
	time_t LastNotifyTime;
	time_t LastSendKeepAliveTime;
	time_t LastAliveResponceTime;
	RecordListCmd CmdRecordList;
	vector<DeviceInfo *> Devices;
	eXosip_t *SipContext;
	UASCallback   Callbacks;
	LoggerId  Loguas;
};

int UASCreate(UASContext **ctx);
int UASStartup(UASContext *ctx);
int UASSetCallback(UASContext *ctx, UASCallback* uasCB);
int UASRegister(UASContext * ctx, int expires);
int UASUnRegister(UASContext * ctx);
int UASKeepAlive(UASContext * ctx);
int UASProcessEvent(UASContext * ctx);
void SendRecordList(UASContext *ctx, const vector<RecordItemInfo>& records);
void SendFileEndMessage(UASContext *ctx, int sid, int did, const char *deviceID);
void NotifyDeviceState(UASContext *ctx, const vector<DeviceInfo> & devicesChanged);
int UASDestroy(UASContext *ctx);
#endif